package com.woody.aggregate.app.web.contract;

import com.woody.aggregate.application.service.contract.ContractService;
import com.woody.aggregate.contract.dto.BatchSaveContractDTO;
import com.woody.aggregate.contract.dto.ContractHaveNewVersionDTO;
import com.woody.aggregate.contract.dto.QueryContractDTO;
import com.woody.aggregate.contract.dto.ManageListDTO;
import com.woody.aggregate.contract.vo.ContractVO;
import com.woody.aggregate.domain.contract.ContractTemplate;
import com.woody.base.model.Response;
import com.woody.common.api.vo.ContractTemplateVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
 * @author hzy
 * @date 2025/2/21 下午5:31
 */
@RestController
@RequestMapping("/contract")
@AllArgsConstructor
@Api(tags = "合同接口")
@Slf4j
public class ContractController {


    @Resource
    private ContractService contractService;


    @GetMapping("/contractList")
    @ApiOperation(value = "店铺合同列表", notes = "店铺合同列表")
    public Response<Map<String,List<ContractVO>>> shopContractList(@RequestParam (value = "customerId") Long customerId,@RequestParam (value = "customerType") Integer customerType){
        Map<String, List<ContractVO>> map = contractService.shopContractList(customerId,customerType);
        return Response.success(map);
    }



    @PostMapping("/haveNewVersion")
    @ApiOperation(value = "是否有新版本合同", notes = "是否有新版本合同")
    public Response<Boolean> haveNewVersion(@RequestBody ContractHaveNewVersionDTO dto){
        Boolean aBoolean = contractService.haveNewVersion(dto);
        return Response.success(aBoolean);
    }


    @PostMapping("/manageList")
    @ApiOperation(value = "合同管理列表", notes = "合同管理列表")
    public Response<List<ContractVO>> manageList(@RequestBody ManageListDTO dto){
        List<ContractVO> contractVOS = contractService.manageList(dto);
        return Response.success(contractVOS);
    }


    @GetMapping("/getTemplate")
    @ApiOperation(value = "获取合同模版", notes = "获取合同模版")
    public Response<ContractTemplateVO> 获取合同模版(@RequestParam (value = "type") String type){
        Map<String, ContractTemplate> templateMap = ContractTemplate.getNewVersionTemplate(Collections.singletonList(type));
        if (templateMap == null){
            return null;
        }
        ContractTemplate contractTemplate = templateMap.get(type);
        return Response.success(contractTemplate);
    }


    @PostMapping("/batchSaveContract")
    @ApiOperation(value = "批量添加合同", notes = "批量添加合同")
    public Response batchSaveContract(@RequestBody BatchSaveContractDTO dto){
        contractService.batchSaveContract(dto);
        return Response.success();
    }

    @PostMapping("/queryContract")
    @ApiOperation(value = "查询合同", notes = "查询合同")
    public Response<ContractVO> queryContract(@RequestBody QueryContractDTO dto){
        ContractVO contractVO = contractService.queryContract(dto);
        return Response.success(contractVO);
    }







}
